home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / misc / PatchGenSrc.lha / Patcher.asm < prev    next >
Assembly Source File  |  1993-07-05  |  5KB  |  311 lines

  1. ;_ args :t/xx ram:x ram:z
  2. ; The Patcher
  3. ; (c) 1993 MJSoft System Software
  4. ; Martin Mares
  5.  
  6. ;    opt    x+
  7.  
  8. _nostart    set    1
  9.     include    "macros.h"
  10.  
  11.     code
  12.     section    Vars,BSS
  13. v
  14.     code
  15.  
  16.     lea    v,a4
  17.     push    a0
  18.     dv.l    dosbase
  19.     lea    dosname(pc),a1
  20.     call    exec,OldOpenLibrary
  21.     pop    a0
  22.     move.l    d0,(a4)
  23.     bne.s    dosok
  24.     moveq    #100,d0
  25.     rts
  26.  
  27.     dbuf    srcname,128
  28.     dbuf    destname,128
  29.     dbuf    patname,128
  30.  
  31. dosok    cmp.b    #'?',(a0)
  32.     bne.s    nohelp
  33.     lea    help(pc),a0
  34.     bra    okmsg
  35.  
  36. nohelp    geta    srcname,a1
  37.     bsr    parsename
  38.     geta    destname,a1
  39.     bsr    parsename
  40.     geta    patname,a1
  41.     bsr    parsename
  42.     bsr    skipspaces
  43.     lea    toomany(pc),a0
  44.     bne    errr
  45.  
  46.     dv.l    srcfile    
  47.     dv.l    srclen
  48.     geta    srcname,a0
  49.     geta    srcfile,a2
  50.     lea    srcerr(pc),a3
  51.     bsr    loadfile
  52.  
  53.     dv.l    patfile
  54.     dv.l    patlen
  55.     geta    patname,a0
  56.     geta    patfile,a2
  57.     lea    paterr(pc),a3
  58.     bsr    loadfile
  59.  
  60.     dv.l    destfile
  61.     dv.l    destlen
  62.  
  63.     get.l    patfile,a2    ; A2=patchfile
  64.     cmp.l    #'MJPa',(a2)+
  65.     bne.s    badpat
  66.     cmp.l    #'tch'*256+1,(a2)+
  67.     beq.s    pat1
  68. badpat    lea    badpatt(pc),a0
  69.     bra    errr
  70.  
  71. pat1    get.l    srclen,d0
  72.     cmp.l    (a2)+,d0
  73.     beq.s    pat2
  74. incfil    lea    incfilt(pc),a0
  75.     bra    errr
  76.  
  77. pat2    get.l    srcfile,a0
  78.     moveq    #0,d1
  79.     moveq    #0,d2
  80. chs1    move.b    (a0)+,d2
  81.     add.l    d2,d1
  82.     ror.l    #1,d1
  83.     subq.l    #1,d0
  84.     bne.s    chs1
  85.     move.l    (a2)+,d0
  86.     cmp.l    (a2)+,d1
  87.     bne.s    incfil
  88.  
  89.     moveq    #1,d1
  90.     call    exec,AllocMem
  91.     move.l    (a4),a6
  92.     lea    imsmem(pc),a0
  93.     put.l    d0,destfile
  94.     beq    errr
  95.     put.l    -8(a2),destlen
  96.     move.l    d0,a3        ; A3=destination
  97.     get.l    srcfile,a0
  98. patit1    moveq    #0,d0
  99.     move.b    (a2)+,d0
  100.     move.l    d0,d1
  101.     lsr.w    #5,d1
  102.     and.w    #$001F,d0
  103.     bne.s    10$
  104.     move.b    (a2)+,d0
  105.     lsl.w    #8,d0
  106.     move.b    (a2)+,d0
  107.     tst.w    d0
  108.     bne.s    10$
  109.     moveq    #3,d7
  110. 11$    lsl.l    #8,d0
  111.     move.b    (a2)+,d0
  112.     dbra    d7,11$
  113. 10$    cmp.w    #6,d1
  114.     bcc    ilgl
  115.     add.w    d1,d1
  116.     move.w    table(pc,d1.w),d1
  117.     jsr    table(pc,d1.w)
  118.     bra.s    patit1
  119.  
  120. rel    macro    *label
  121.     dc.w    \1-table
  122.     endm
  123. table    rel    patend
  124.     rel    change
  125.     rel    insert
  126.     rel    delete
  127.     rel    skip
  128.     rel    xorins
  129.  
  130. ilgl    lea    errpatt(pc),a0
  131.     bra    errr
  132.  
  133. change    add.l    d0,a0
  134. insert    move.b    (a2)+,(a3)+
  135.     subq.l    #1,d0
  136.     bne.s    insert
  137.     rts
  138.  
  139. delete    add.l    d0,a0
  140.     rts
  141.  
  142. skip    move.b    (a0)+,(a3)+
  143.     subq.l    #1,d0
  144.     bne.s    skip
  145.     rts
  146.  
  147. xorins    push    a0
  148.     get.l    srcfile,a1
  149.     move.l    a1,a0
  150.     add.l    srclen-v(a4),a1
  151. xorins1    cmp.l    a1,a0
  152.     bcs.s    1$
  153.     get.l    srcfile,a0
  154. 1$    move.b    (a0)+,d1
  155.     move.b    (a2)+,d2
  156.     eor.b    d1,d2
  157.     move.b    d2,(a3)+
  158.     subq.l    #1,d0
  159.     bne.s    xorins1
  160.     pop    a0
  161.     rts
  162.  
  163. patend    addq.l    #4,sp
  164.     move.l    a3,d0
  165.     sub.l    destfile-v(a4),d0
  166.     cmp.l    destlen-v(a4),d0
  167.     bne.s    ilgl
  168.  
  169.     geta    destname,a0
  170.     move.l    a0,d1
  171.     move.l    #1006,d2
  172.     call    Open
  173.     lea    wrterr(pc),a0
  174.     move.l    d0,d7
  175.     beq    errr
  176.     get.l    destfile,d2
  177.     get.l    destlen,d3
  178.     call    Write
  179.     move.l    d0,d2
  180.     move.l    d7,d1
  181.     call    Close
  182.     lea    wrterr(pc),a0
  183.     cmp.l    d2,d3
  184.     bne    errr
  185.  
  186.     lea    donet(pc),a0
  187.     bra    okmsg
  188.  
  189. loadfile    move.l    (a4),a6
  190.     move.l    a0,d1
  191.     move.l    #1005,d2
  192.     call    Open
  193.     move.l    a3,a0
  194.     move.l    d0,d7
  195.     beq    sperr
  196.     move.l    d0,d1
  197.     moveq    #0,d2
  198.     moveq    #1,d3
  199.     call    Seek
  200.     move.l    d7,d1
  201.     moveq    #-1,d3
  202.     call    Seek
  203.     move.l    d0,d3
  204.     moveq    #1,d1
  205.     call    exec,AllocMem
  206.     move.l    (a4),a6
  207.     move.l    d0,(a2)+
  208.     bne.s    mem1ok
  209.     move.l    d7,d1
  210.     call    Close
  211. insmem    lea    imsmem(pc),a0
  212.     bra    sperr
  213. mem1ok    move.l    d0,d2
  214.     move.l    d3,(a2)
  215.     move.l    d7,d1
  216.     call    Read
  217.     move.l    d0,d2
  218.     move.l    d7,d1
  219.     call    Close
  220.     move.l    a3,a0
  221.     cmp.l    d2,d3
  222.     bne.s    sperr
  223.     rts
  224.  
  225. argerr    lea    toofew(pc),a0
  226. sperr    addq.l    #4,a7
  227. errr    bsr    puts
  228.     moveq    #10,d7
  229.     bra.s    cleanup
  230.  
  231. okmsg    bsr    puts
  232. okay    moveq    #0,d7    ; ReturnCode
  233. cleanup    move.l    4.w,a6
  234.     get.l    srclen,d0
  235.     beq.s    1$
  236.     get.l    srcfile,a1
  237.     call    FreeMem
  238. 1$    get.l    patlen,d0
  239.     beq.s    2$
  240.     get.l    patfile,a1
  241.     call    FreeMem
  242. 2$    get.l    destlen,d0
  243.     beq.s    3$
  244.     get.l    destfile,a1
  245.     call    FreeMem
  246. 3$    move.l    (a4),a1
  247.     call    CloseLibrary
  248.     move.l    d7,d0
  249.     rts
  250.  
  251. skipspaces    move.b    (a0)+,d0
  252.     beq.s    skipspend
  253.     cmp.b    #' ',d0
  254.     beq.s    skipspaces
  255.     cmp.b    #9,d0
  256.     beq.s    skipspaces
  257.     cmp.b    #10,d0
  258. skipspend    rts
  259.  
  260. parsename    bsr.s    skipspaces
  261.     beq    argerr
  262.     move.b    d0,d1
  263.     cmp.b    #'"',d0
  264.     beq.s    1$
  265.     subq.l    #1,a0
  266.     moveq    #' ',d1
  267. 1$    move.b    (a0)+,d0
  268.     beq.s    2$
  269.     cmp.b    #10,d0
  270.     beq.s    2$
  271.     cmp.b    d1,d0
  272.     beq.s    3$
  273.     move.b    d0,(a1)+
  274.     bra.s    1$
  275. 2$    subq.l    #1,a0
  276.     cmp.b    #' ',d1
  277.     beq.s    3$
  278.     lea    badargs(pc),a0
  279.     bra    sperr
  280. 3$    sf    (a1)+
  281.     rts
  282.  
  283. puts    move.l    a0,d2
  284. 1$    tst.b    (a0)+
  285.     bne.s    1$
  286.     subq.l    #1,a0
  287.     move.l    a0,d3
  288.     sub.l    d2,d3
  289.     move.l    (a4),a6
  290.     call    Output
  291.     jump    Write
  292.  
  293. dosname    dc.b    'dos.library',0
  294. help    dc.b    'The Patcher 1.1'
  295.     dc.b    '                  '
  296.     dc.b    '(c) 1993 MJSoft System Software, Martin Mares',10,10
  297.     dc.b    'Usage: Patcher <source> <destination> <patch table>',10
  298.     dc.b    0
  299. toomany    dc.b    'Too many arguments!',10,0
  300. toofew    dc.b    'Required argument missing!',10,0
  301. badargs    dc.b    'Invalid arguments!',10,0
  302. srcerr    dc.b    'Unable to read source file!',10,0
  303. paterr    dc.b    'Unable to read patch file!',10,0
  304. imsmem    dc.b    'Insufficient memory!',10,0
  305. badpatt    dc.b    'Not a patch file!',10,0
  306. errpatt    dc.b    'Corrupted patch file!',10,0
  307. incfilt    dc.b    'Invalid source file for this patch table!',10,0
  308. donet    dc.b    'Done.',10,0
  309. wrterr    dc.b    'Unable to open output file!',10,0
  310.     even
  311.